package cn.com.nes.site.action.monitor;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.com.nes.common.util.DBUtils;
import cn.com.nes.common.util.XzqhUtil;
import cn.com.nes.site.entity.DataReq;
import cn.com.nes.site.entity.DataRes;
import cn.com.nes.site.entity.PageData;
import cn.com.nes.site.module.service.monitor.MapService;

@Controller("map")
@RequestMapping("/map")
public class MapAction {

	@Resource
	private MapService service;
	
	//获取项目数量
	@RequestMapping(method = RequestMethod.POST, value = "/getProjectLocation")
	public @ResponseBody  PageData getProjectLocation(HttpServletRequest request,
			HttpServletResponse response, ModelMap modelMap) throws Exception {
			DataRes req_Status = DBUtils.setRemoteVisit(request, response,true);
			PageData res = new PageData() ;
			if (req_Status.getRetCode() != 0) {
				res = new PageData();
				res.setRetCode(req_Status.getRetCode()) ;
				res.setRetMessage(req_Status.getRetMessage());
				return res;
			}	
			DataReq req = req_Status.getReq() ;
			res = service.getProjectLocation(req) ;
			return res;
	}
	
	//获取设备数量
	@RequestMapping(method = RequestMethod.POST, value = "/getDeviceCount")
	public @ResponseBody  PageData getDeviceCount(HttpServletRequest request,
			HttpServletResponse response, ModelMap modelMap) throws Exception {
			DataRes req_Status = DBUtils.setRemoteVisit(request, response,true);
			PageData res = new PageData() ;
			if (req_Status.getRetCode() != 0) {
				res = new PageData();
				res.setRetCode(req_Status.getRetCode()) ;
				res.setRetMessage(req_Status.getRetMessage());
				return res;
			}	
			DataReq req = req_Status.getReq() ;
			res = service.getDeviceCount(req) ;
			return res;
	}

	/**
	 * 按地区分组，查询设备总数及在线、离线数量
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(method = RequestMethod.POST, value = "/getCountOfDeviceGroupByArea")
	@ResponseBody
	public PageData getCountOfDeviceGroupByArea(HttpServletRequest request,HttpServletResponse response) throws Exception {
		DataRes reqStatus = DBUtils.setRemoteVisit(request, response, true);
		PageData res;
		if (reqStatus.getRetCode() != 0) {
			res = new PageData();
			res.setRetCode(reqStatus.getRetCode());
			res.setRetMessage(reqStatus.getRetMessage());
			return res;
		}
		res = service.getCountOfDeviceGroupByArea(reqStatus.getReq());
		return res;
	}

	/**
	 * 按设备使用类型分组，查询设备的数量、在线数量、在线率
	 */
	@RequestMapping(method = RequestMethod.POST, value = "/getCountAndRateOfDeviceGroupByType")
	@ResponseBody
	public PageData getCountAndRateOfDeviceGroupByType(HttpServletRequest request,HttpServletResponse response) throws Exception {
		DataRes reqStatus = DBUtils.setRemoteVisit(request, response, true);
		PageData res;
		if (reqStatus.getRetCode() != 0) {
			res = new PageData();
			res.setRetCode(reqStatus.getRetCode());
			res.setRetMessage(reqStatus.getRetMessage());
			return res;
		}
		res = service.getCountAndRateOfDeviceGroupByType(reqStatus.getReq());
		return res;
	}

	/**
	 * 查询新增设备
	 */
	@RequestMapping(method = RequestMethod.POST, value = "/getNewDevice")
	@ResponseBody
	public PageData getNewDevice(HttpServletRequest request,HttpServletResponse response) throws Exception {
		DataRes reqStatus = DBUtils.setRemoteVisit(request, response, true);
		PageData res;
		if (reqStatus.getRetCode() != 0) {
			res = new PageData();
			res.setRetCode(reqStatus.getRetCode());
			res.setRetMessage(reqStatus.getRetMessage());
			return res;
		}
		res = service.getNewDevice(reqStatus.getReq());
		return res;
	}

	/**
	 * 按设备型号查询设备销售趋势
	 */
	@RequestMapping(method = RequestMethod.POST, value = "/getDeviceSaleTrendGroupByDeviceModel")
	@ResponseBody
	public PageData getDeviceSaleTrendGroupByDeviceModel(HttpServletRequest request,HttpServletResponse response) throws Exception {
		DataRes reqStatus = DBUtils.setRemoteVisit(request, response, true);
		PageData res;
		if (reqStatus.getRetCode() != 0) {
			res = new PageData();
			res.setRetCode(reqStatus.getRetCode());
			res.setRetMessage(reqStatus.getRetMessage());
			return res;
		}
		res = service.getDeviceSaleTrendGroupByDeviceModel(reqStatus.getReq());
		return res;
	}

	/**
	 * 按时间查询代理商数量
	 */
	@RequestMapping(method = RequestMethod.POST, value = "/getAgentSaleTrendByTime")
	@ResponseBody
	public PageData getAgentSaleTrendByTime(HttpServletRequest request,HttpServletResponse response) throws Exception {
		DataRes reqStatus = DBUtils.setRemoteVisit(request, response, true);
		PageData res;
		if (reqStatus.getRetCode() != 0) {
			res = new PageData();
			res.setRetCode(reqStatus.getRetCode());
			res.setRetMessage(reqStatus.getRetMessage());
			return res;
		}
		res = service.getAgentSaleTrendByTime(reqStatus.getReq());
		return res;
	}

	/**
	 * 按月份分组设备销售趋势（商用、户用）
	 */
	@RequestMapping(method = RequestMethod.POST, value = "/getDeviceTypeSaleTrendGroupByMonth")
	@ResponseBody
	public PageData getDeviceTypeSaleTrendGroupByMonth(HttpServletRequest request,HttpServletResponse response) throws Exception {
		DataRes reqStatus = DBUtils.setRemoteVisit(request, response, true);
		PageData res;
		if (reqStatus.getRetCode() != 0) {
			res = new PageData();
			res.setRetCode(reqStatus.getRetCode());
			res.setRetMessage(reqStatus.getRetMessage());
			return res;
		}
		res = service.getDeviceTypeSaleTrendGroupByMonth(reqStatus.getReq());
		return res;
	}

	/**
	 * 行政区划（省）分组查询设备故障和预警，可按时间查询
	 */
	@RequestMapping(method = RequestMethod.POST, value = "/getFaultAndWarnForDeviceGroupByProvinceOnTime")
	@ResponseBody
	public PageData getFaultAndWarnForDeviceGroupByProvinceOnTime(HttpServletRequest request,HttpServletResponse response) throws Exception {
		DataRes reqStatus = DBUtils.setRemoteVisit(request, response, true);
		PageData res;
		if (reqStatus.getRetCode() != 0) {
			res = new PageData();
			res.setRetCode(reqStatus.getRetCode());
			res.setRetMessage(reqStatus.getRetMessage());
			return res;
		}
		res = service.getFaultAndWarnForDeviceGroupByProvinceOnTime(reqStatus.getReq());
		return res;
	}

	/**
	 * 地图展示设备相关数据
	 */
	@RequestMapping(method = RequestMethod.POST, value = "/getDeviceRelateDataForMap")
	@ResponseBody
	public PageData getDeviceRelateDataForMap(HttpServletRequest request,HttpServletResponse response) throws Exception {
		DataRes reqStatus = DBUtils.setRemoteVisit(request, response, true);
		PageData res;
		if (reqStatus.getRetCode() != 0) {
			res = new PageData();
			res.setRetCode(reqStatus.getRetCode());
			res.setRetMessage(reqStatus.getRetMessage());
			return res;
		}
		res = service.getDeviceRelateDataForMap(reqStatus.getReq());
		return res;
	}

	/**
	 *	根据省份查看设备详情
	 */
	@RequestMapping(method = RequestMethod.POST, value = "/getDeviceDataDetailsByProvince")
	@ResponseBody
	public PageData getDeviceDataDetailsByProvince(HttpServletRequest request,HttpServletResponse response) throws Exception {
		DataRes reqStatus = DBUtils.setRemoteVisit(request, response, true);
		PageData res;
		if (reqStatus.getRetCode() != 0) {
			res = new PageData();
			res.setRetCode(reqStatus.getRetCode());
			res.setRetMessage(reqStatus.getRetMessage());
			return res;
		}
		res = service.getDeviceDataDetailsByProvince(reqStatus.getReq());
		return res;
	}

	/**
	 * 查询线索转化及销售排名
	 */
	@RequestMapping(method = RequestMethod.POST, value = "/getClueTranslateAndSalesRanking")
	@ResponseBody
	public PageData getClueTranslateAndSalesRanking(HttpServletRequest request,HttpServletResponse response) throws Exception {
		DataRes reqStatus = DBUtils.setRemoteVisit(request, response, true);
		PageData res;
		if (reqStatus.getRetCode() != 0) {
			res = new PageData();
			res.setRetCode(reqStatus.getRetCode());
			res.setRetMessage(reqStatus.getRetMessage());
			return res;
		}
		res = service.getClueTranslateAndSalesRanking(reqStatus.getReq());
		return res;
	}

}
